package com.ruoyi.square.like.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.square.like.domain.Like;
import com.ruoyi.square.like.service.ILikeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点赞功能Controller
 * 
 * @author myd
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/like/like")
public class LikeController extends BaseController
{
    @Autowired
    private ILikeService likeService;

    /**
     * 查询点赞功能列表
     */
    @PreAuthorize("@ss.hasPermi('like:like:list')")
    @GetMapping("/list")
    public TableDataInfo list(Like like)
    {
        startPage();
        List<Like> list = likeService.selectLikeList(like);
        return getDataTable(list);
    }

    /**
     * 导出点赞功能列表
     */
    @PreAuthorize("@ss.hasPermi('like:like:export')")
    @Log(title = "点赞功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Like like)
    {
        List<Like> list = likeService.selectLikeList(like);
        ExcelUtil<Like> util = new ExcelUtil<Like>(Like.class);
        util.exportExcel(response, list, "点赞功能数据");
    }

    /**
     * 获取点赞功能详细信息
     */
    @PreAuthorize("@ss.hasPermi('like:like:query')")
    @GetMapping(value = "/{likeId}")
    public AjaxResult getInfo(@PathVariable("likeId") Long likeId)
    {
        return success(likeService.selectLikeByLikeId(likeId));
    }

    @GetMapping("/checkDuplicate")
    public AjaxResult checkDuplicate(
            @RequestParam Long userId,
            @RequestParam Long dynamicId,
            @RequestParam Long commentId
    ) {
        Like existLike = likeService.selectLikeByUserAndContent(userId, dynamicId, commentId);
        return success(existLike != null);
    }

    /**
     * 新增点赞功能
     */
    @PreAuthorize("@ss.hasPermi('like:like:add')")
    @Log(title = "点赞功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Like like)
    {
        return toAjax(likeService.insertLike(like));
    }

    /**
     * 修改点赞功能
     */
    @PreAuthorize("@ss.hasPermi('like:like:edit')")
    @Log(title = "点赞功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Like like)
    {
        return toAjax(likeService.updateLike(like));
    }

    /**
     * 删除点赞功能
     */
    @PreAuthorize("@ss.hasPermi('like:like:remove')")
    @Log(title = "点赞功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeIds}")
    public AjaxResult remove(@PathVariable Long[] likeIds)
    {
        return toAjax(likeService.deleteLikeByLikeIds(likeIds));
    }
}
